//操作的格式化
goodsFormatter = function (value, row, index) {

    // if (row.isSpecial == 1) {
    //     return ['<a class="find" href="javascript:void(0)" >查看商品详细</a>&nbsp;&nbsp;' +
    //     '<a class="jiaoyijilu" href="javascript:void(0)" >交易记录</a>&nbsp;&nbsp;' +
    //     '<a class="xiajia" href="javascript:void(0)" >下架</a>&nbsp;&nbsp;' +
    //     '<a class="removeSpecial" href="javascript:void(0)" >取消特价</a>&nbsp;&nbsp;' +
    //     '<a class="gene2code" href="javascript:void(0)">生成二维码</a>'].join('');
    // } else {
    return ['<a class="find" href="javascript:void(0)" >查看商品详细</a>' +
    '&nbsp;&nbsp;' +
    '<a class="jiaoyijilu" href="javascript:void(0)" >交易记录</a>' +
    '&nbsp;&nbsp;' +
    '<a class="xiajia" href="javascript:void(0)" style="color: red">下架</a>' +
    '&nbsp;&nbsp;'
        // '<a class="gene2code" href="javascript:void(0)">生成二维码</a>'
    ].join('');
    // }
};

priceFormatter = function (value, row, index) {
    var myDate = new Date();
    var year = myDate.getFullYear();    //获取完整的年份(4位,1970-????)
    var month = myDate.getMonth() + 1;       //获取当前月份(0-11,0代表1月)
    var day = myDate.getDate();        //获取当前日(1-31)
    var hous = myDate.getHours();       //获取当前小时数(0-23)
    var minutes = myDate.getMinutes().toString();   //获取当前分钟数(0-59)
    if (minutes.length < 2) {
        var sec = "0" + minutes;
    } else if (minutes.length == 2) {
        var sec = minutes;
    }
    var seconds = myDate.getSeconds();    //获取当前毫秒数(0-999)

    var time = year + "-" + month + "-" + day + " " + hous + ":" + sec + ":" + seconds; //系统时间
    var exTime = row.expirationTime; //特价时间
    if (exTime != null) {
        var num = Date.parse(exTime);
    }
    var da = Date.parse(time);
    if (num - da <= 0) {
        $.post($().AbsUrlParse("/web/goods/noUpper"), {id: row.id, special: 2}, function (data) {
            if (data.state == true) {
                if (data.res.code == 40000) {
                    var table = $('#table');
                    table.bootstrapTable('refresh');
                } else {
                    hint(data.res.msg);
                }
            } else {
                hint(data.msg);
            }
        });
    }
    if (num - da > 0 && row.isSpecial == 1) {
        return "<span style='color:#00ca6d;'>是</span>";
    } else if (num - da < 0 || row.isSpecial == 0) {
        return "<span >否</span>";
    } else if (num - da <= 0) {
        return "<span style='color:red;'>特价已到期</span>";
    }
};


// var shoujias = function (value, row, index) {
//     var expirationTime = row.expirationTime;
//     expirationTime = Date.parse(expirationTime);
//     var presentTimestamp = Date.parse(new Date());
//     if (expirationTime > presentTimestamp && row.isSpecial == 1) {
//         return row.price;
//     } else {
//         return value;
//     }
// }


expirationTime = function (value, row, index) {
    var expirationTime = row.expirationTime;
    if (expirationTime == null) {
        return "<span>该商品不是特价商品</span>";
    } else {
        return ['<span> ' + expirationTime + '</span>'].join();
    }
};

headPicFormatter = function (value, row, index) {
    var img = row.headPic;
    var imgs = img.split(",");
    var imgUrl = "";
    if (img != null && img != "") {
        imgUrl = File_Download_Url + imgs[0];
        return '<image src=' + imgUrl + ' style="width:80px;height:80px" onclick="enlargeImage(this)"/>';
    } else {
        return '<image src=' + $().AbsUrlParse("/static/images/no.png") + ' style="width:80px;height:80px" onclick="enlargeImage(this)"/>'
    }
};

//查询商品
bindClick("#goodsSelect", function () {
    var goodsName = $("input[name=goodsName1]").val();
    var isSpecial = $("select[name=isSpecial]").val();
    var bussName = $("input[name=bussName]").val();
    var type = $("#type").val();
    var url = $().AbsUrlParse("/web/goods/findGoods?goodsName=" + goodsName + "&isSpecial=" + isSpecial + "&bussName=" + bussName + "&type=" + type);
    $("#table").bootstrapTable("refresh", {url: url});
});


window.goodsEvent = {
    'click .find': function (e, value, row, index) {
        // $("#showimages").html("");
        showModel("show-div", function () {
            $("#oldPrice").val(row.oldPrice);
            $("#price").val(row.price);
            $("#bagging").val(row.bagging);
            $("#stock").val(row.stock);
            $("#detail").val(row.goodsDetail);
            var p = "";
            if (row.params == 1) {
                p = '支持';
            } else {
                p = '不支持';
            }
            $("#params").val(p);
            var img = row.images;
            console.log(img)
            var imgs = "";
            if (img != null || img != "") {
                var imgArr = img.split(",");
                for (var i = 0; i < imgArr.length; i++) {
                    if (imgArr[i] != "" && imgArr[i] != null) {
                        var imgUrl = File_Download_Url + imgArr[i];
                        imgs += '<image src=' + imgUrl + ' style="width:150px;height:150px" onclick="enlargeImage(this)"/>&nbsp;&nbsp;&nbsp;';
                    }
                }
                $("#showimages").html(imgs);
            } else {
                imgs = '<image src=' + $().AbsUrlParse("/static/images/no.png") + ' style="width:260px;height:210px" onclick="enlargeImage(this)"/>';
                $("#showimages").html(imgs);
            }
        })
    },
    'click .jiaoyijilu': function (e, value, row, index) {
        showModel("jiaoyijilu-div", function () {
            $("#id").val(row.id);
            var url = $().AbsUrlParse("/web/goods/jiaoYiDetail?id=" + row.id);
            $("#table1").bootstrapTable("refresh", {url: url});
        })
    },
    'click .xiajia': function (e, value, row, index) {
        comment.showOperationTips("确定该商品下架吗？", function () {
            $.post($().AbsUrlParse("/web/goods/noUpper"), {id: row.id}, function (data) {
                if (data.state == true) {
                    if (data.res.code == 40000) {
                        closeModel("finddetail-div");
                        hint("操作成功,该产品已经下架");
                        var table = $('#table');
                        table.bootstrapTable('refresh');
                    } else {
                        hint(data.res.msg);
                    }
                } else {
                    hint(data.msg);
                }
            });
        })
    },
    'click .removeSpecial': function (e, value, row, index) {
        comment.showOperationTips("你确定取消特价商品吗？", function () {
            $.post($().AbsUrlParse("/web/goods/removeSpecial"), {
                id: row.id
            }, function (data) {
                if (data.state == true) {
                    if (data.res.code == 40000) {
                        hint("操作成功");
                        var table = $('#table');
                        table.bootstrapTable('refresh');
                    } else {
                        hint(data.res.msg);
                    }
                } else {
                    hint(data.msg);
                }
            });
        });
    }
    //
    // 'click .gene2code': function (e, value, row, index) {     //生成二维码
    //     if ($("#qrcode canvas").length != 0) {
    //         $("#qrcode canvas").each(function () {
    //             $(this).remove();
    //         });
    //     }
    //     var str = "";
    //     if (row.id != 0) {
    //         str = "id:" + row.id + ',' + "type:product" + ',' + "bId:" + row.bId;
    //
    //     }
    //     showModel("code2-div", function () {
    //         $("#qrcode").qrcode({
    //             render: "canvas",
    //             width: 180,
    //             height: 180,
    //             text: str
    //         });
    //     });
    // }
};

payTypeFormatter = function (value, row, index) {
    var pay = row.pay_type;
    if (pay == 1) {
        return [
            '<div><span >' + '支付宝' + '</span></div> '
        ].join('');
    } else if (pay == 2) {
        return [
            '<div ><span >' + '微信' + '</span></div> '
        ].join('');
    } else if (pay == 3) {
        return [
            '<div ><span >' + '支付宝 + 红包' + '</span></div> '
        ].join('');
    } else if (pay == 4) {
        return [
            '<div ><span >' + '微信 + 红包' + '</span></div> '
        ].join('');
    } else {
        return [
            '<div ><span >' + '红包抵扣' + '</span></div> '
        ].join('');
    }
};


orderStatus = function (value, row, index) {
    if (value == 1) {
        return '<span style="color:red">待付款</span>';
    } else if (value == 2) {
        return '<span style="color:blue">待接单</span>';
    } else if (value == 3) {
        return '<span style="color:green">待配送</span>';
    } else if (value == 4) {
        return '<span style="color:orange">配送中</span>';
    } else if (value == 5) {
        return '<span style="color:purple">待评价</span>';
    } else if (value == 6) {
        return '<span style="color:#FFF68F">已完结</span>';
    } else if (value == 7) {
        return '<span style="color:#A0522D">申请退款</span>';
    } else if (value == 8) {
        return '<span style="color:darkolivegreen">拒绝接单</span>';
    } else if (value == 9) {
        return '<span style="color:lightskyblue">同意退款</span>';
    } else if (value == 10) {
        return '<span style="color:lightcoral">拒绝退款</span>';
    } else if (value == 11) {
        return '<span style="color:midnightblue">用户取消</span>';
    } else if (value = 12) {
        return '待取货';
    }
};

//查询商品
bindClick("#orderDetailSelect", function () {
    var jyjltimeS = $("#jyjltimeS").val();
    var jyjlzffs = $("#jyjlzffs").val();
    var ids = $("#id").val();
    var url = $().AbsUrlParse("/web/goods/jiaoYiDetail?cstart=" + jyjltimeS + "&jyjlzffs=" + jyjlzffs + "&id=" + ids);
    $("#table1").bootstrapTable("refresh", {url: url});
});

var getGoodsType = function () {
    $.post($().AbsUrlParse("/web/goods/queryGoodsType"), null, function (id) {
        var select = $("#type");
        select.empty();
        select.append('<option value="-1">-请选择商品分类-</option>');
        if (id.res.code == 40000) {
            var allData = id.res.data;
            for (var i = 0; i < allData.length; i++) {
                select.append('<option value="' + allData[i].id + '">' + allData[i].name + '</option>');
            }
        }
    });
};
getGoodsType();

function enlargeImage(value) {
    showModel("detailImage-div", function () {
        var imgs = '<image src=' + value.src + ' style="height:500px" />';
        $("#image").html(imgs);
    })
}

function enlargeImage(value) {
    showModel("detailImage-div", function () {
        var imgs = '<image src=' + value.src + ' style="height:500px" />';
        $("#image").html(imgs);
    })
}

